package com.mail.server.controller;


import com.mail.model.db.PmsProduct;
import com.mail.model.dto.ProductParamDto;
import com.mail.model.dto.QueryProductDto;
import com.mail.model.vo.PageResult;
import com.mail.server.common.R;
import com.mail.server.service.PmsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品信息 前端控制器
 * </p>
 *
 * @author WJZ
 * @since 2022-06-20
 */
@RestController
@RequestMapping("/product")
public class PmsProductController {
    @Autowired
    private PmsProductService productService;

    /**
     * AppServerApplication
     * 新建商品
     *
     * @param paramDto
     * @return
     */
    @PostMapping("/create")
    public R createProduct(@RequestBody ProductParamDto paramDto) {
        productService.createProduct(paramDto);
        return R.success(null);
    }

    /**
     * 查询商品
     *
     * @param queryProductDto
     * @return
     */
    @GetMapping("/list")
    public R queryProductList(QueryProductDto queryProductDto) {
        PageResult pageResult = productService.queryProductList(queryProductDto);
        return R.success(pageResult);
    }

    /**
     * 根据商品名称或货号模糊查询
     *
     * @param keyword
     * @return
     */
    @GetMapping("/simpleList")
    public R simpleList(String keyword) {
        List<PmsProduct> pmsProductList = productService.queryProductByKeyword(keyword);
        return R.success(pmsProductList);

    }

    /**
     * 批量修改删除状态
     *
     * @return
     */
    @PostMapping("/update/deleteStatus")
    public R deleteStatus(@RequestParam List<Integer> ids, Integer deleteStatus) {
        productService.deleteStatus(deleteStatus, ids);
        return R.success(null);
    }

    /**
     * 批量设为新品
     *
     * @return
     */
    @PostMapping("/update/newStatus")
    public R newStatus(@RequestParam List<Integer> ids, Integer newStatus) {
        productService.newStatus(newStatus, ids);
        return R.success(null);
    }

    /**
     * 批量上下架商品
     *
     * @return
     */
    @PostMapping("/update/publishStatus")
    public R publishStatus(Integer publishStatus, @RequestParam List<Integer> ids) {
        productService.publishStatus(publishStatus, ids);
        return R.success(null);
    }

    /**
     * 批量推荐商品
     *
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public R recommendStatus(@RequestParam List<Integer> ids, Integer recommendStatus) {
        productService.recommendStatus(recommendStatus, ids);
        return R.success(null);
    }

    /**
     * 批量修改审核状态
     *
     * @return
     */
    @PostMapping("/update/verifyStatus")
    public R verifyStatus(@RequestParam List<Integer> ids, Integer verifyStatus, String detail) {
        productService.verifyStatus(detail, verifyStatus, ids);
        return R.success(null);
    }

    /**
     * 更新商品
     *
     * @param id
     * @param productParamDto
     * @return
     */
    @PostMapping("/update/{id}")
    public R updateProduct(@PathVariable Integer id, @RequestBody ProductParamDto productParamDto) {
        productService.updateProduct(id, productParamDto);
        return R.success(null);
    }

    /**
     * 根据商品id获取商品编辑信息
     *
     * @return
     */
    @GetMapping("/updateInfo/{id}")
    public R queryByProductId(@PathVariable Integer id) {
        ProductParamDto productParamDto = productService.queryByProductId(id);
        return R.success(productParamDto);
    }


}
